Linux Quickstart π§π
Published at Nov 27, 2024
π Introduction
Welcome to this quick start guide for Linux! The goal isnβt to memorize every command, but to understand the workflow and learn how to learn. Stick around for a bonus tip at the end! π
Basic Commands
ls - List Directory Contents ποΈ
When you first open a terminal, it might feel like a dark and empty abyss. Letβs turn
on the lights with ls π‘.
- What it does: Lists information about files and directories. By default, it sorts entries alphabetically.
- Finding out more: Use
man lsto see the manual page.
Common Parameters (Flags)
Parameters modify how a command works. They usually have a short (-a) and
long (--all) form.
-aor--all: Show all entries, including hidden files (those starting with.).-l: Use a long listing format. This shows permissions, owner, group, size, modification date, and filename.-ror--reverse: Reverse the order of the sort.-t: Sort by modification time, newest first. Combine with-lto see the times (ls -lt).
Example Usage:
# Basic listing
ls
# List all files
# (including hidden)
ls -a
# Long listing format
ls -l
# Long listing
# of all files
ls -al
# Long listing,
# all files,
# reversed order
ls -alr
# Long listing,
# sorted by time
# (newest first)
ls -lt Quick Tip: Use
Ctrl+Lto clear the terminal screen.
man - The System Manual π
man is your key π to understanding commands.
- What it does: Displays the systemβs reference manuals (manual pages) for commands, utilities, or functions. It uses a pager program like
lessto display the content. - Usage:
man <command_name>(e.g.,man ls,man man).
Navigating man Pages (using less)
Press h inside man for a help screen.
- Moving:
β/βorEnter: Move down/up one line.Spacebar/PageDown: Move down one page.PageUp: Move up one page.
- Jumping:
gg: Go to the beginning of the page.G(Shift+g): Go to the end of the page.
- Searching:
/search_term: Search forward forsearch_term.?search_term: Search backward forsearch_term.n: Go to the next search result (in the direction you searched).N(Shift+n): Go to the previous search result.
- Quitting:
q: Quit themanpage viewer.
Example: Letβs find the time sorting option in ls.
- Open the manual:
man ls - Search forward for βtimeβ:
/time - Press
nto cycle through results until you find the-tflag.
Navigating the File System πΊοΈ
Understanding the Hierarchy π
The Linux file system is a hierarchy, like an inverted tree π³ or a staircase, starting from the root directory (/).
- Root Directory:
/- The top level. - Home Directory:
/home/<username>(e.g.,/home/crispy) - Your personal space. - Path Separator:
/- Used to separate directories in a path.
You can visualize the structure using the
treecommand
cd - Change Directory
- What it does: Changes your current working directory.
Paths
- Absolute Path: Specifies the location from the root directory (
/). Always starts with/.- Example:
cd /home/crispy/Documents
- Example:
- Relative Path: Specifies the location relative to your current directory. Does not start with
/..(dot): Represents the current directory...(dot-dot): Represents the parent directory (one level up).- Example: If you are in
/home/crispy:cd Documents(orcd ./Documents) moves into theDocumentssubdirectory.cd ..moves up to/home.
Example Workflow:
# Check current directory
# (e.g., /home/crispy)
pwd
# Go to home using absolute path
cd /home/crispy
# Confirm: /home/crispy
pwd
# Go down into Documents
# (relative path)
cd Documents
# Confirm:
# /home/crispy/Documents
pwd
# Go up one level
# (relative path)
cd ..
# Confirm:
# /home/crispy
pwd pwd - Print Working Directory
- What it does: Shows the full path of your current directory.
Viewing Files π
cat - Concatenate and Display Files π
- What it does: Reads files sequentially and writes their content to standard output (your terminal).
- Concatenation: If you provide multiple filenames,
catdisplays them one after the other.
Example Usage:
# Display a single file
cat reminder.txt
# Display multiple files,
# one after the other
cat file1.txt file2.txt file3.txt Bonus: Quick References with curl and cheat.sh π
Sometimes you just need a quick reminder or example. cheat.sh is a community-driven cheat sheet service accessible via curl π.
curl - Transfer Data from URLs
- What it does: A versatile tool to transfer data using various protocols, including HTTP/HTTPS for web pages.
- Basic Usage:
curl <url>
cheat.sh - Command Cheat Sheets
- Access:
curl cheat.sh - Get help for a specific command:
curl cheat.sh/<command_name> - Short alias: Often,
cht.shworks too:curl cht.sh/<command_name>
Example Usage:
# General help/intro
curl cheat.sh
# Cheat sheet for ls
curl cheat.sh/ls
# Cheat sheet for grep
curl cht.sh/grep
# Cheat sheet for tar
curl cheat.sh/tar cheat.sh provides common use cases, explanations, and often a TL;DR section for very quick examples. Explore the :help and :intro sections (curl cheat.sh/:help).
Conclusion π―
Weβve covered the basics:
ls: Listing files ποΈman: Reading manuals πcd,pwd: Navigating directories π²cat: Viewing files πcurl,cheat.sh: Getting quick help π
The key is not memorizing absolutely everything π§ but knowing how to find information (
man,cheat.sh) and understanding how Linux works from a high level πΈ
Keep exploring, stay curious, and practice! π